﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Catsland.Core;
using System.ComponentModel;

namespace Catsland.CatsPlugin
{
	public class Breakable : CatComponent
	{
		private int m_hp=6;
        [CategoryAttribute("Basic")]
        public int HP
        {
            get { return m_hp; }
            set { m_hp = value; }
        }

		public Breakable(GameObject gameObject)
			: base(gameObject)
		{
		}

		public void GetHurt(GameObject attacker)
		{
			m_hp -= 1;

            Animator animator = (Animator)m_gameObject.GetComponent(typeof(Animator).Name);

			// animation
			if (m_hp > 3)
			{
                if (animator != null)
				{
                    animator.PlayAnimation("AllBreak");
				}
			}

			// destroy
			else if (m_hp <= 3 && m_hp > 0)
			{
                if (animator != null)
				{
                    animator.PlayAnimation("HalfBreak");
				}
				
			}

			else if (m_hp <= 0)
			{
				Mgr<Scene>.Singleton._gameObjectList.RemoveItem(m_gameObject._guid);
			}
		}

		public override bool SaveToNode(XmlNode node, XmlDocument doc)
		{
			XmlElement breakable = doc.CreateElement("Breakable");
			node.AppendChild(breakable);

			return true;
		}

        public override void ConfigureFromNode(XmlElement node, Scene scene, GameObject gameObject)
        {
            base.ConfigureFromNode(node, scene, gameObject);

            return;
        }

	}
}
